import * as request from '../constant/fetch-request'
import HTTP_CODE from '../constant/http-code'

export const GET_USER_ORGANIZATIONS = 'GET_USER_ORGANIZATIONS'

export const getUserOrganizations = (userId) => {
  return dispatch => {
    (async () => {
      const res = await request.get(`../api/organizations/users/${userId}?role=instructor`)
      if (res.status === HTTP_CODE.OK) {
        dispatch({
          type: GET_USER_ORGANIZATIONS,
          data: res.body
        })
      }
    })()
  }
}
